<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title>编辑课程 - 企业培训平台</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .form-container {
            max-width: 600px;
            margin: 20px auto;
            padding: 30px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #333;
        }
        .form-group input[type="text"],
        .form-group input[type="number"],
        .form-group textarea,
        .form-group select {
            width: calc(100% - 22px);
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 1em;
            box-sizing: border-box; /* Include padding and border in the element's total width and height */
        }
        .form-group textarea {
            resize: vertical;
            min-height: 100px;
        }
        .form-actions {
            text-align: right;
            margin-top: 20px;
        }
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1em;
            text-decoration: none;
            display: inline-block;
            transition: background-color 0.3s ease;
        }
        .btn-primary {
            background-color: #007bff;
            color: white;
        }
        .btn-primary:hover {
            background-color: #0056b3;
        }
        .btn-secondary {
            background-color: #6c757d;
            color: white;
            margin-left: 10px;
        }
        .btn-secondary:hover {
            background-color: #5a6268;
        }
        .error-message {
            color: #dc3545;
            margin-bottom: 15px;
            text-align: center;
        }
        .success-message {
            color: #28a745;
            margin-bottom: 15px;
            text-align: center;
        }
        .current-image {
            margin-top: 10px;
            margin-bottom: 10px;
            text-align: center;
        }
        .current-image img {
            max-width: 200px;
            height: auto;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div th:replace="~{fragments/header :: header}"></div>
<div class="main-content">
    <div class="form-container">
        <h2 th:text="'编辑课程:' + ${course.couName}">编辑课程</h2>
        <div th:if="${errorMessage}" class="error-message">
            <p th:text="${errorMessage}"></p>
        </div>
        <div th:if="${successMessage}" class="success-message">
            <p th:text="${successMessage}"></p>
        </div>

        <form th:action="@{/course/edit/{id}(id=${course.id})}" th:object="${course}" method="post" enctype="multipart/form-data">
            <input type="hidden" th:field="*{id}" />
            <input type="hidden" th:field="*{teaId}" />
            <input type="hidden" th:field="*{couTypeId}" />
            <input type="hidden" th:field="*{couParTypeId}" />

            <div class="form-group">
                <label for="couName">课程名称:</label>
                <input type="text" id="couName" th:field="*{couName}" required>
            </div>

            <div class="form-group">
                <label for="couIntroduction">课程简介:</label>
                <textarea id="couIntroduction" th:field="*{couIntroduction}"></textarea>
            </div>

            <div class="form-group">
                <label>当前课程封面:</label>
                <div class="current-image" th:if="*{couPic != null and !couPic.isEmpty()}">
                    <img th:src="@{${course.couPic}}" alt="课程封面">
                </div>
                <div th:unless="*{couPic != null and !couPic.isEmpty()}">
                    <p>暂无课程封面</p>
                </div>
                <label for="couPic">上传新封面 (可选):</label>
                <input type="file" id="couPic" name="couPicFile" accept="image/*">
            </div>

            <div class="form-group">
                <label for="couPrice">课程价格 (积分):</label>
                <input type="number" id="couPrice" th:field="*{couPrice}" min="0" required>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary">保存修改</button>
                <a th:href="@{/course/manage}" class="btn btn-secondary">取消</a>
            </div>
        </form>
    </div>
</div>

<div th:replace="fragments/footer :: footer"></div>
</body>
</html>